/*
Calculates the member forces (tension/compression) for a simply supported
bridge with basic straight members.
*/

#include <allegro5/allegro.h>
#include <iostream>

#include "core/bridge.h"

// includes for mvc application architecture
#include "mvc/allegrowrapper.h"

#include "gui/model_bridge.h"
#include "gui/view_main.h"
#include "gui/control_main.h"

Bridge buildBridge1();

int main(int argc, char **argv) {
    // the following line prevents a screwy error:
    std::cout << std::endl;

    // test mvc architecture
    ModelBridge* model = new ModelBridge();
    ViewMain* master_view = new ViewMain();
    ControlMain* main_controller = new ControlMain();

    main_controller->setView(master_view);
    main_controller->setModel(model);

    MASTER->setModel(model);
    MASTER->setView(master_view);
    MASTER->addChild(main_controller);

    master_view->removeChild(master_view);

    MASTER->setFirstResponder(main_controller);

    if(MASTER->initAll()) MASTER->go();

    // test bridge analysis
    Bridge mybridge = buildBridge1();
    mybridge.solve();
    mybridge.printResults();

    return 0;
}

Bridge buildBridge1() {
    Bridge bridge;
    Member member1, member2, member3;
    Point point1, point2, point3;

    // create points
    point1.setX(0);
    point1.setY(0);
    point1.setID(0);
    point1.setAnchorFull();

    point2.setX(1);
    point2.setY(1);
    point2.setID(1);
    point2.setExtY(-100);

    point3.setX(1.5);
    point3.setY(0);
    point3.setID(2);
    point3.setAnchorHalf();

    // create members
    member1.setPoint1(point1);
    member1.setPoint2(point2);
    bridge.addMember(member1);

    member2.setPoint1(point2);
    member2.setPoint2(point3);
    bridge.addMember(member2);

    member3.setPoint1(point1);
    member3.setPoint2(point3);
    bridge.addMember(member3);

    return bridge;
}

